package cn.sc.allinpay.allfavour.business.payment;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import cn.pai.mvp.callback.MpCallBack;
import cn.sc.allinpay.allfavour.base.connect.http.AppRequest;
import cn.sc.allinpay.allfavour.base.connect.http.RequestManager;
import cn.sc.allinpay.allfavour.base.model.BaseModel;
import cn.sc.allinpay.allfavour.business.common.data.SpOrderInfo;

/**
 * 去支付
 * author：pany
 * on 2017/12/5 14:44
 */
public class PaymentModel extends BaseModel {

    public void spScan(final String authCode, final String paymentAmount, final String spOrderId,final String spOrderCode, final MpCallBack<SpOrderInfo, String> mpCallBack) {
        RequestManager.spScan(authCode, paymentAmount, spOrderId, spOrderCode, new AppRequest.PosRequestCall() {
            @Override
            protected void onSuccess(JSONObject response) {
                SpOrderInfo orderInfo = JSON.parseObject(response.getString("data"), SpOrderInfo.class);
                mpCallBack.onSuccess(orderInfo);
            }

            @Override
            public void onFailure(JSONObject response, String message) {
                mpCallBack.onFailure(response != null ? response.toString() : null, message);
            }
        });
    }

    public void payNotify(final String order_id, final String trans_way, final String traxstatus, final String trans_time, final String c_amount, final String a_amount, final  String transactionNumber, final MpCallBack<JSONObject, String> mpCallBack) {
        RequestManager.payNotify(order_id, trans_way, traxstatus, trans_time, c_amount, a_amount, transactionNumber, new AppRequest.RequestCall() {
            @Override
            protected void onSuccess(JSONObject response) {
                mpCallBack.onSuccess(response);
            }

            @Override
            public void onFailure(JSONObject response, String message) {
                mpCallBack.onFailure(response != null ? response.toString() : null, message);
            }
        });
    }

    /**
     * 创建商点订单
     *
     */
    public void spCreateOrder(String amount, String outOrderNo, final MpCallBack<SpOrderInfo, String> mpCallBack) {
        RequestManager.spCreateOrder(amount, outOrderNo, new AppRequest.PosRequestCall() {
            @Override
            protected void onSuccess(JSONObject response) {
                SpOrderInfo orderInfo = response.getObject("data", SpOrderInfo.class);
                mpCallBack.onSuccess(orderInfo);
            }
            @Override
            public void onFailure(JSONObject response, String message) {
                mpCallBack.onFailure(response != null ? response.toString() : null, message);
            }
        });
    }
}
